{% extends "app/base_site.html" %}

{% block title %} 轮巡管理 {% endblock title %}

{% block stylesheets %}
  {{ block.super }}
{% endblock stylesheets %}

{% block content %}

  <div class="right_col" role="main">
    <div class="">
      <div class="row">
          <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
              <div class="x_title">
               <h2>轮巡管理
                    <span id="top_loading" ><img class="top_loading_img" src="/static/images/load.gif" alt="loading">加载中</span>
                    <span id="top_msg">{{top_msg}}</span>
               </h2>
                <div class="clearfix"></div>
              </div>
              <div class="x_content">

                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr class="headings">
                        <th class="column-title">ID</th>
                        <th class="column-title">名称</th>
                        <th class="column-title">轮巡并发</th>
                        <th class="column-title">轮巡时长</th>
                        <th class="column-title">轮巡状态</th>
                        <th class="column-title">更新时间</th>
                          <th class="column-title last"><span class="nobr">操作</span></th>
                      </tr>
                    </thead>

                    <tbody>
                    {%  for d  in data %}
                      <tr class="even pointer">
                        <td>{{ d.id }}</td>
                        <td>{{ d.name }}</td>
                        <td>{{ d.control_concurrency }}</td>
                        <td>{{ d.control_duration }}</td>
                        <td>
                            {% if d.is_run == 1 %}
                                <span class="sun-state-success">轮巡中</span>
                            {% else %}
                                  <span class="sun-state-error">未轮巡</span>
                            {% endif %}
                        </td>

                          <td>{{ d.last_update_time }}</td>
                        <td>
                            <div class="btn-group">

                                {% if d.is_run == 1 %}
                                    <button onclick="f_postHandlePatrol('{{ d.code }}','cancel')" class="btn btn-dark btn-sm">取消轮巡</button>
                               {% else %}
                                    <button onclick="f_postHandlePatrol('{{ d.code }}','add')" class="btn btn-default btn-sm">执行轮巡</button>
                                {% endif %}
                                <button onclick="f_view('{{ d.code }}')" class="btn btn-sm btn-default" type="button" title="预览"><i class="fa fa-play-circle"></i></button>

                                <button onclick="f_edit('{{ d.code }}')" class="btn btn-sm btn-default" type="button" title="编辑"><i class="fa fa-edit"></i></button>
                                <button onclick="f_del('{{ d.code }}')" class="btn btn-sm btn-default" type="button" title="删除"><i class="fa fa-remove"></i></button>
                            </div>
                        </td>
                      </tr>
                    {% endfor %}

                    </tbody>
                  </table>
                </div>


              </div>
            </div>
          </div>
      </div>

      <div class="row">
          <div class="col-md-12 col-sm-12 col-xs-12">
            <ul class="pagination">
                <li>
                    <span style="margin-right:10px;color:#000;">共<span>{{ pageData.page_num}}</span>页 / <span>{{pageData.count}}</span >条</span>
                </li>

                {%  for d  in pageData.pageLabels%}
                  {% if d.cur == 1 %}
                    <li class="paginate_button active"><a href="#"  >{{ d.name }}</a></li>
                  {% else %}
                    <li class="paginate_button "><a href="/controlPatrol/index?p={{d.page}}&ps={{pageData.page_size}}" >{{ d.name }}</a></li>
                  {% endif %}
                {% endfor %}

            </ul>

          </div>
       </div>


    </div>
  </div>

{% endblock content %}

{% block javascripts %}
  {{ block.super }}

<script>
    let ele_top_loading = $("#top_loading");
    let ele_top_msg= $("#top_msg");

    function f_postHandlePatrol(code,handle) {
        let url;
        if(handle === "add"){
            url = '/controlPatrol/openStartPatrol';
        }else if(handle === "cancel"){
            url = '/controlPatrol/openStopPatrol';
        }else{
            return;
        }

        ele_top_loading.show();
        $.ajax({
               url: url,
               type: "post",
               async: true,
               data: {"code":code},
               dataType: "json",
               timeout: 0,
               error: function () {
                   ele_top_loading.hide();
                   myToast2025("网络异常，请确定网络正常！","error");
               },
               success: function (res) {
                   ele_top_loading.hide();
                   if(1000 === res.code){
                        window.location.reload();
                   }else{
                        myToast2025(res.msg,"error");
                   }
               }
            });
    }
    function f_view(code) {
        let url = "/controlPatrol/view?code="+code;
        window.location.href = url;
    }
    function f_edit(code) {
        let url = "/controlPatrol/edit?code="+code;
        window.location.href = url;
    }
    function f_del(code){
        ele_top_loading.show();
        $.ajax({
               url: '/controlPatrol/openDel',
               type: "post",
               async: true,
               data: {"code":code},
               dataType: "json",
               timeout: 0,
               error: function () {
                   ele_top_loading.hide();
                   myToast2025("网络异常，请确定网络正常！","error");
               },
               success: function (res) {
                      ele_top_loading.hide();
                   if(1000 === res.code){
                        window.location.reload();
                   }else{
                        myToast2025(res.msg,"error");
                   }
               }
            });
    }


</script>

{% endblock javascripts %}

